package com.avecsys.quotemanager.validators;

import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.validator.ValidatorException;

import com.avecsys.quotemanager.utils.MessageBoardUtil;
import com.avecsys.quotemanager.utils.UIComponentUtils;
import com.icesoft.faces.component.ext.HtmlInputSecret;

public class ValidatorPasswordChangePasswordSame extends BaseValidator {

	public FacesMessage validateFieldValue(FacesContext facesContext,
			UIComponent uIComponent, Object object) throws ValidatorException {
		String passwordValue = (String) object;
		FacesMessage message = new FacesMessage();
		HtmlInputSecret confirmPasswordField = (HtmlInputSecret) uIComponent
				.getParent().findComponent("confirmPasswordId");
		if (passwordValue != null
				&& UIComponentUtils.isEmpty(confirmPasswordField)) {
			if (!passwordValue.equals(confirmPasswordField.getSubmittedValue()))
				message.setSummary(MessageBoardUtil.getValue(facesContext,
						"commonMsgs",
						"VALIDATION_PASSWORD_CHANGE_PASSWORD_NOT_SAME", null));
		}
		return message;
	}
}
